import logging
import allure,time
import pytest
from data.constant import *
from base.base_action import BaseAction
from base.base_analyze import analyze_data

@allure.feature('网校运营中心/订单管理')  # 所属模块
class TestCase72OrganizationMgt(object):
    """
    BLOCKER = 'blocker'  阻塞的
    CRITICAL = 'critical'  危险的
    NORMAL = 'normal'  正常的
    MINOR = 'minor'  次要的
    TRIVIAL = 'trivial' 不重要的
    """
    @allure.severity(severity_level="normal")  # 严重级别
    @allure.story("TestCase72OrganizationMgt001_【基线用例】后台/订单管理/订单列表：创建线下收费订单成功")# 用例标题
    @allure.testcase("暂无禅道链接")# 禅道链接
    # @pytest.mark.parametrize("login_hjx",[],indirect = True)
    def testCase03CreateOrder001(self,login_hjx):
        logging.info('开始执行测试用例====》')
        login_hjx.pageOrdermanagement.click_order_management()   # 点击切换订单管理菜单
        time.sleep(2)
        login_hjx.pageOrdermanagement.click_menu_order_list()  # 点击订单列表
        time.sleep(2)
        login_hjx.pageProductList.click_switch_to()  # 切换iframe
        login_hjx.pageOrdermanagement.click_create_order()  # 点击创建订单
        login_hjx.pageOrdermanagement.click_create_all(name='自动化学员', product_name='自考学院',examination_name='2023',
                                                       project_type='学历自考')  # 创建线下订单
        time.sleep(3)
        assert "创建订单成功" in login_hjx.pageOrdermanagement.created_successfully_text(), "用例成功"


    @allure.severity(severity_level="normal")  # 严重级别
    @allure.story("TestCase72OrganizationMgt001_【基线用例】后台/订单管理/订单列表：创建线上收费订单成功")# 用例标题
    @allure.testcase("暂无禅道链接")# 禅道链接
    # @pytest.mark.parametrize("login_hjx",[],indirect = True)
    def testCase03CreateOrder002(self,login_hjx):
        logging.info('开始执行测试用例====》')
        login_hjx.pageOrdermanagement.click_order_management()   # 点击切换订单管理菜单
        time.sleep(2)
        login_hjx.pageOrdermanagement.click_menu_order_list()  # 点击订单列表
        time.sleep(2)
        login_hjx.pageProductList.click_switch_to()  # 切换iframe
        login_hjx.pageOrdermanagement.click_create_order()  # 点击创建订单
        login_hjx.pageOrdermanagement.click_create_all_01(name='自动化学员', product_name=PRODUCT_NAME, price=PRICE,
                                                          examination_name='2023', project_type='学历自考')  # 创建线上订单
        time.sleep(1)
        assert "创建订单成功" in login_hjx.pageOrdermanagement.created_successfully_text(), "用例成功"


    @allure.severity(severity_level="normal")  # 严重级别
    @allure.story("TestCase72OrganizationMgt001_【基线用例】后台/订单管理/订单列表：订单收费成功")# 用例标题
    @allure.testcase("暂无禅道链接")# 禅道链接
    # @pytest.mark.parametrize("login_hjx",[],indirect = True)
    def testCase03OrdeFree003(self, login_hjx):
        logging.info('开始执行测试用例====》')
        login_hjx.pageOrdermanagement.click_order_management()   # 点击切换订单管理菜单
        time.sleep(2)
        login_hjx.pageOrdermanagement.click_menu_order_list()  # 点击订单列表
        time.sleep(2)
        login_hjx.pageProductList.click_switch_to()  # 切换iframe
        login_hjx.pageOrdermanagement.click_order_charge()  # 第一条订单收费
        time.sleep(1)
        login_hjx.pageOrdermanagement.click_manual_charge(prie1='1000')     # 订单收费
        time.sleep(1.5)
        # assert "收费成功!" == login_hjx.pageOrdermanagement.get_charge_success(), "用例成功"


    @allure.severity(severity_level="normal")  # 严重级别
    @allure.story("TestCase72OrganizationMgt001_【基线用例】后台/订单管理/订单列表：异动换产品")# 用例标题
    @allure.testcase("https://chandao.mshiedu.com/zentao/testcase-view-45267--testcase-0.html")# 禅道链接
    # @pytest.mark.parametrize("login_hjx",[],indirect = True)
    def testCase03ChangeProducts004(self, login_hjx):
        logging.info('开始执行测试用例====》')
        login_hjx.pageOrdermanagement.click_order_management()   # 点击切换订单管理菜单
        time.sleep(2)
        login_hjx.pageOrdermanagement.click_menu_order_list()  # 点击订单列表
        time.sleep(2)
        login_hjx.pageProductList.click_switch_to()  # 切换iframe
        login_hjx.pageOrdermanagement.click_after_servicet(explain=EXPLAIN, money=0, product_name=PRODUCT_NAME, price=PRICE)    # 异动换产品
        time.sleep(2)
        assert "申请时间" == login_hjx.pageOrdermanagement.get_time_application(), "用例成功"


    @allure.severity(severity_level="normal")  # 严重级别
    @allure.story("TestCase72OrganizationMgt001_【基线用例】后台/订单管理/订单列表：异动仅退款")# 用例标题
    @allure.testcase("https://chandao.mshiedu.com/zentao/testcase-view-45265--testcase-0.html")# 禅道链接
    # @pytest.mark.parametrize("login_hjx",[],indirect = True)
    def testCase03RefundOnly005(self, login_hjx):
        logging.info('开始执行测试用例====》')
        login_hjx.pageOrdermanagement.click_order_management()   # 点击切换订单管理菜单
        time.sleep(2)
        login_hjx.pageOrdermanagement.click_menu_order_list()  # 点击订单列表
        time.sleep(2)
        login_hjx.pageProductList.click_switch_to()  # 切换iframe
        login_hjx.pageOrdermanagement.click_refund_only(explain=EXPLAIN, money1=10,  payee=PAYEE, account=ACCOUNT) # 异动退学退费
        time.sleep(2)
        assert "申请时间" == login_hjx.pageOrdermanagement.get_time_application(), "用例成功"


    @allure.severity(severity_level="normal")  # 严重级别
    @allure.story("TestCase72OrganizationMgt001_【基线用例】后台/订单管理/订单列表：异动退学退费")# 用例标题
    @allure.testcase("https://chandao.mshiedu.com/zentao/testcase-view-45266--testcase-0.html")# 禅道链接
    # @pytest.mark.parametrize("login_hjx",[],indirect = True)
    def testCase03WithdrawalFee006(self, login_hjx):
        logging.info('开始执行测试用例====》')
        login_hjx.pageOrdermanagement.click_order_management()   # 点击切换订单管理菜单
        time.sleep(2)
        login_hjx.pageOrdermanagement.click_menu_order_list()  # 点击订单列表
        time.sleep(2)
        login_hjx.pageProductList.click_switch_to()  # 切换iframe
        login_hjx.pageOrdermanagement.click_withdrawal_fee(explain=EXPLAIN, money1=10,  payee=PAYEE, account=ACCOUNT) # 异动退学退费
        time.sleep(2)
        assert "申请时间" == login_hjx.pageOrdermanagement.get_time_application(), "用例成功"

    @allure.severity(severity_level="normal")  # 严重级别
    @allure.story("TestCase72OrganizationMgt001_【基线用例】后台/订单管理/订单列表：作废计费单，作废成功")# 用例标题
    @allure.testcase("暂无禅道链接")# 禅道链接
    # @pytest.mark.parametrize("login_hjx",[],indirect = True)
    def testCase03eeOrderDeleteBill07(self, login_hjx):
        logging.info('开始执行测试用例====》')
        login_hjx.pageOrdermanagement.click_order_management()   # 点击切换订单管理菜单
        time.sleep(2)
        login_hjx.pageOrdermanagement.click_menu_order_list()  # 点击订单列表
        time.sleep(2)
        login_hjx.pageProductList.click_switch_to()  # 切换iframe
        login_hjx.pageOrdermanagement.click_create_order()  # 点击创建订单
        login_hjx.pageOrdermanagement.click_create_all_01(name='自动化学员', product_name=PRODUCT_NAME, price=PRICE,
                                                          examination_name='2023', project_type='学历自考')  # 创建线上订单
        login_hjx.pageOrdermanagement.click_order_charge()  # 第一条订单收费
        time.sleep(1)
        login_hjx.pageOrdermanagement.click_manual_charge(prie1='1000')     # 订单收费流程
        login_hjx.pageOrdermanagement.click_check()  # 点击查看
        time.sleep(3)
        login_hjx.pageOrdermanagement.click_cancel_bill()   # 作废计费单
        time.sleep(2)
        assert "作废成功" == login_hjx.pageOrdermanagement.get_successful_cancellation(), "用例成功"



    @allure.severity(severity_level="normal")  # 严重级别
    @allure.story("TestCase72OrganizationMgt001_【基线用例】后台/订单管理/订单列表：订单详情页订单收费")# 用例标题
    @allure.testcase("暂无禅道链接")# 禅道链接
    # @pytest.mark.parametrize("login_hjx",[],indirect = True)
    def testCase03eeOrderDeleteBill08(self, login_hjx):
        logging.info('开始执行测试用例====》')
        login_hjx.pageOrdermanagement.click_order_management()   # 点击切换订单管理菜单
        time.sleep(2)
        login_hjx.pageOrdermanagement.click_menu_order_list()  # 点击订单列表
        time.sleep(2)
        login_hjx.pageProductList.click_switch_to()  # 切换iframe
        login_hjx.pageOrdermanagement.click_check()  # 点击查看
        time.sleep(3)
        login_hjx.pageOrdermanagement.click_detail_order_charge()   # 订单收费
        login_hjx.pageOrdermanagement.click_manual_charge(prie1='1000')     # 订单收费流程
        time.sleep(2)
        assert "收费成功！" == login_hjx.pageOrdermanagement.click_detail_charge_successe(), "用例成功"

    @allure.severity(severity_level="normal")  # 严重级别
    @allure.story("testCaseteeOrderOperation09_【基线用例】后台/订单管理/订单列表：推送订单推送成功")# 用例标题
    @allure.testcase("https://chandao.mshiedu.com/zentao/testcase-view-45269--testcase-0.html")# 禅道链接
    # @pytest.mark.parametrize("login_hjx",[],indirect = True)
    def testCase03eeOrderOperation09(self, login_hjx):
        logging.info('开始执行测试用例====》')
        login_hjx.pageOrdermanagement.click_order_management()   # 点击切换订单管理菜单
        time.sleep(2)
        login_hjx.pageOrdermanagement.click_menu_order_list()  # 点击订单列表
        time.sleep(2)
        login_hjx.pageProductList.click_switch_to()  # 切换iframe
        login_hjx.pageOrdermanagement.click_check()   # 点击查看
        time.sleep(3)
        login_hjx.pageOrdermanagement.click_push_order()    # 点击推送
        assert "推送成功" == login_hjx.pageOrdermanagement.get_check_push(), "用例成功"

    @allure.severity(severity_level="normal")  # 严重级别
    @allure.story("TestCase72OrganizationMgt001_【基线用例】后台/订单管理/订单列表：订单变动")# 用例标题
    @allure.testcase("暂无禅道链接")# 禅道链接
    # @pytest.mark.parametrize("login_hjx",[],indirect = True)
    def testCase03eeOrderchang10(self, login_hjx):
        logging.info('开始执行测试用例====》')
        login_hjx.pageOrdermanagement.click_order_management()   # 点击切换订单管理菜单
        time.sleep(2)
        login_hjx.pageOrdermanagement.click_menu_order_list()  # 点击订单列表
        time.sleep(2)
        login_hjx.pageProductList.click_switch_to()  # 切换iframe
        login_hjx.pageOrdermanagement.click_check()     # 点击查看
        time.sleep(3)
        login_hjx.pageOrdermanagement.click_order_change()  # 订单变动
        assert "变动成功" == login_hjx.pageOrdermanagement.get_change_sucess(), "用例成功"

    @allure.severity(severity_level="normal")  # 严重级别
    @allure.story("TestCase72OrganizationMgt001_【基线用例】后台/订单管理/订单列表：修改业务归属人-成功")# 用例标题
    @allure.testcase("暂无禅道链接")# 禅道链接
    # @pytest.mark.parametrize("login_hjx",[],indirect = True)
    def testCase03eeOrderAlter11(self, login_hjx):
        logging.info('开始执行测试用例====》')
        login_hjx.pageOrdermanagement.click_order_management()   # 点击切换订单管理菜单
        time.sleep(2)
        login_hjx.pageOrdermanagement.click_menu_order_list()  # 点击订单列表
        time.sleep(2)
        login_hjx.pageProductList.click_switch_to()  # 切换iframe
        login_hjx.pageOrdermanagement.click_check()     # 点击查看
        time.sleep(1)
        login_hjx.pageOrdermanagement.click_business_owner(business_name="韦超君")  # 订单变动
        assert "修改成功" == login_hjx.pageOrdermanagement.get_alter_suceess(), "用例成功"

    @allure.severity(severity_level="normal")  # 严重级别
    @allure.story("testCaseteeCacellOrder12_【基线用例】后台/订单管理/订单列表：作废订单成功")# 用例标题
    @allure.testcase("https://chandao.mshiedu.com/zentao/testcase-view-45271--testcase-0.html")# 禅道链接
    # @pytest.mark.parametrize("login_hjx",[],indirect = True)
    def testCase03eeCacellOrder12(self, login_hjx):
        logging.info('开始执行测试用例====》')
        login_hjx.pageOrdermanagement.click_order_management()   # 点击切换订单管理菜单
        time.sleep(2)
        login_hjx.pageOrdermanagement.click_menu_order_list()  # 点击订单列表
        time.sleep(2)
        login_hjx.pageProductList.click_switch_to()  # 切换iframe
        login_hjx.pageOrdermanagement.click_check()     # 点击查看
        time.sleep(3)
        login_hjx.pageOrdermanagement.click_cancelled_order()  # 作废订单
        time.sleep(3)
        assert "作废成功" == login_hjx.pageOrdermanagement.get_successful_cancellation(), "用例成功"

    @allure.severity(severity_level="normal")  # 严重级别
    @allure.story("TestCase72OrganizationMgt001_【基线用例】后台/订单管理/订单列表：导入订单")# 用例标题
    @allure.testcase("暂无禅道链接")# 禅道链接
    # @pytest.mark.parametrize("login_hjx",[],indirect = True)
    def testCase03eeCaceImportOrd13(self, login_hjx):
        logging.info('开始执行测试用例====》')
        login_hjx.pageOrdermanagement.click_order_management()   # 点击切换订单管理菜单
        time.sleep(2)
        login_hjx.pageOrdermanagement.click_menu_order_list()  # 点击订单列表
        time.sleep(2)
        login_hjx.pageProductList.click_switch_to()  # 切换iframe
        login_hjx.pageOrdermanagement.click_import_file(file_path=FILE_PATH)    # 导入订单流程
        # time.sleep(0.5)
        assert "任务已提交" in login_hjx.pageOrdermanagement.get_task_submitted(), "用例成功"
        time.sleep(2)
        login_hjx.pageOrdermanagement.click_refresh_page()  # 点击刷新

    @allure.severity(severity_level="normal")  # 严重级别
    @allure.story("TestCase72OrganizationMgt001_【基线用例】后台/订单管理/计费单列表：红冲计费单")# 用例标题
    @allure.testcase("https://chandao.mshiedu.com/zentao/testcase-view-45264--testcase-0.html")# 禅道链接
    # @pytest.mark.parametrize("login_hjx",[],indirect = True)
    def testCase03eeCaceImportOrd14(self, login_hjx):
        logging.info('开始执行测试用例====》')
        login_hjx.pageOrdermanagement.click_order_management()   # 点击切换订单管理菜单
        time.sleep(2)
        login_hjx.pageOrdermanagement.click_menu_order_list()  # 点击订单列表
        time.sleep(2)
        login_hjx.pageProductList.click_switch_to()  # 切换iframe
        login_hjx.pageOrdermanagement.click_order_charge()  # 第一条订单收费
        time.sleep(1)
        login_hjx.pageOrdermanagement.click_manual_charge(prie1='1000')     # 订单收费
        time.sleep(1.5)
        login_hjx.pageOrdermanagement.click_order_charge()  # 第一条订单收费
        login_hjx.pageOrdermanagement.click_manual_charge(prie1='1000')     # 订单收费
        time.sleep(2)
        login_hjx.pageOrdermanagement.swich_default()   # 从frame中切换到主界面
        time.sleep(2)
        login_hjx.pageOrdermanagement.click_billing_list()  # 点击计费单列表
        time.sleep(1)
        login_hjx.pageProductList.click_switch_to()  # 切换iframe
        login_hjx.pageOrdermanagement.click_billing_processself()   # 红冲计费单流程
        assert "已红冲" == login_hjx.pageOrdermanagement.get_red_stamp(), "用例成功"
